import axios from 'axios'
import commonUrl from '../api/js/commonUrl'
import qs from 'qs'

// 地址选择信息
export function getdata() {
  const url =  `${commonUrl.apiurl}index.php/home/Proprietorauth/getHouses?areas_id=204`
  return axios({
    method: 'GET',
    url: url
  }).then(res => {
    return Promise.resolve(res.data)
  }).catch(err => {
    return Promise.reject(err)
  })
}

// 地址选择2数据
export function getdata2() {
  const url = 'https://ynwx.zgwyzxw.cn/index.php/admin/index/index1'
  return axios({
    method: 'GET',
    url: url
  }).then(res => {
    return Promise.resolve(res.data)
  }).catch(err => {
    return Promise.reject(err)
  })
}

// 首页房屋公告求助等信息
export function getVillageList() {
  const url = `${commonUrl.apiurl}index.php/home/Index/recentAnnounce/?areas_id=204&city_code=3301&city_name='杭州'&user_id=888`
  return axios({
    method: 'GET',
    url: url
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 通过微信jssdk 获取经纬度
export function getConfig () {
  const data = {
    url: window.location.href.split('#')[0]
  }
  return axios({
    method: 'POST',
    url: `${commonUrl.apiurl}index.php/wx/wx_jssdk/getSignPackage`,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data)
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 治理透明
//收入信息
export function getInCome () {
  const url = `${commonUrl.apiurl}index.php/home/Govern/getIncome?areasId=204`
  return axios({
    method: 'GET',
    url: url
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 支出数据
export function getPay () {
  const url = `${commonUrl.apiurl}index.php/home/Govern/getexpenditure?areasId=204`
  return axios({
    method: 'GET',
    url: url
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 透明治理汇总部分的数据
export function getSummary () {
  const url = `${commonUrl.apiurl}index.php/home/Govern/summary?areasId=204`
  return axios({
    method: 'GET',
    url: url
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {

    return Promise.reject(err)
  })
}

// 话题部分
// 热门话题数据
// 论坛数据列表
export function getMangerOne () {
  const url = `${commonUrl.apiurl}index.php/home/forum/index/?areas_id=204`
  return axios({
    method: 'GET',
    url: url
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 搜索
export function searchKeyword (keyword) {
  return axios({
    method: 'GET',
    url: `${commonUrl.apiurl}index.php/home/city/search2?key=${keyword}&cityId=3`
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}


// 投票信息
export function voteData() {
  const url = 'https://ynwx.zgwyzxw.cn/index.php/applets/Satisfaction_Vote/satisfactionVoteNewDetail'
  const data = {
    satisId: 13,
    type: 'vote'
  }
  return axios({
    method: 'POST',
    url: url,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data)
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}
